package com.adou.p2p.controller;

import io.swagger.annotations.Api;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.adou.p2p.base.controller.AbstractBaseApiController;
import com.adou.p2p.base.controller.ContentType;
import com.adou.p2p.model.UserValue;
import com.adou.p2p.service.UserService;

@RestController
@RequestMapping("/")
@Api(tags = "user")
public class UserController extends AbstractBaseApiController {
	@Autowired
	private UserService userService;

	@GetMapping(value = "/users", produces = { ContentType.PRODUCTS_1_0 })
	public ResponseEntity<List<UserValue>> getUsers() {
		List<UserValue> values = userService.getUsers();
		return new ResponseEntity<List<UserValue>>(values, HttpStatus.OK);
	}

//	@GetMapping(value = "/users/{id}", produces = { ContentType.PRODUCT_1_0 })
//	public ResponseEntity<ProductValue> getProduct(@PathVariable("id") long id) {
//		try {
//			ProductValue branch = productService.getProduct(id);
//			return new ResponseEntity<>(branch, HttpStatus.OK);
//		} catch (Exception e) {
//			throw new NotFoundException(e.getMessage());
//		}
//	}
//
//	@PostMapping(value = "users", consumes = { ContentType.PRODUCT_1_0 }, produces = { ContentType.PRODUCT_1_0 })
//	public ResponseEntity<ProductValue> createProduct(@Valid @RequestBody ProductValue productValue) {
//		ProductValue product = productService.createProduct(productValue);
//		MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
//		headers.add(HttpHeaders.LOCATION, "products" + product.getId());
//		return new ResponseEntity(product, headers, HttpStatus.CREATED);
//	}
//
//	@PutMapping(value = "/products/{id}", consumes = { ContentType.PRODUCT_1_0 }, produces = {
//			ContentType.PRODUCT_1_0 })
//	ResponseEntity<ProductValue> updateProduct(@PathVariable long id, @Valid @RequestBody ProductValue productValue) {
//		productValue.setId(id);
//		try {
//			ProductValue product = productService.updateProduct(productValue);
//			return new ResponseEntity<>(product, HttpStatus.OK);
//		} catch (Exception e) {
//			throw new NotFoundException(e.getMessage());
//		}
//
//	}
//
//	@DeleteMapping("products/{id}")
//	ResponseEntity<Void> deleteProduct(@PathVariable int id) {
//		try {
//			productService.deleteProductById(id);
//			return new ResponseEntity(null, HttpStatus.NO_CONTENT);
//		} catch (Exception e) {
//			throw new NotFoundException(e.getMessage());
//		}
//	}
//
//	@GetMapping(value = "/async/products", produces = { ContentType.PRODUCTS_1_0 })
//	public CompletableFuture<ResponseEntity<List<ProductValue>>> aynecGetProducts() {
//		List<ProductValue> productValues = productService.getProducts();
//		return CompletableFuture.completedFuture(new ResponseEntity<>(productValues, HttpStatus.OK));
//
//	}
//
//	@GetMapping(value = "/async/products/{id}", produces = { ContentType.PRODUCT_1_0 })
//	public CompletableFuture<ResponseEntity<ProductValue>> asyncGetProduct(@PathVariable("id") long id) {
//		return CompletableFuture.completedFuture(getProduct(id));
//	}
//
//	@ApiOperation("分页查询")
//	@GetMapping("page")
//	public ResponseVo<String> qryProductPage(@RequestParam(required = false) String name,
//			@RequestParam(required = false, defaultValue = "1") Integer pageNumber,
//			@RequestParam(required = false, defaultValue = "2") Integer pageSize) {
//
//		ProductValue dto = ProductValue.builder().name(name).build();
//
//		PageResult<ProductValue> result = productService.qryProductValuePage(pageNumber, pageSize, null, null, dto);
//		ResponseVo.Page pageVo = new ResponseVo.Page(pageNumber, pageSize, (int) result.getTotalElements());
//
//		return result.getContent() != null ? ResponseVo.success(result.getContent(), pageVo)
//				: ResponseVo.failtrue(ErrorCode.SELECT_ERROR, "我发获取产品信息");
//
//	}

}
